local AddOnName, Env = ...; local ADDON, DEV = Env[1], Env[1].DEV
-- ~~| Libraries |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local AceConfigDialog 	= LibStub("AceConfigDialog-3.0")
local AceConfigRegistry	= LibStub("AceConfigRegistry-3.0")
-- ~~| Lua Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~| WoW Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local SetCVar						= SetCVar
-- ~~|  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function ADDON:OpenOptions()
	AceConfigDialog:Open(AddOnName)
	AceConfigDialog.OpenFrames[AddOnName].status.groups.treewidth = 100 -- CBF using GetStatusTable
	AceConfigRegistry:NotifyChange(AddOnName)	
end
-- ~~| Default Database |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADDON.defaults = {
	global = {
		enabled = true,
		locked = false,
		minimap = {
			hide = false,
		},
		debug = {},			
	},
	profile = {					
		remote = {
			executeCount = true,				
			width = 250,
			alpha = 100,					
		},
		actionLog = {					
			tooltips 	= true,
			width			= 420,		
			height 		= 218,								
		},
		rotationSelecter = {
			show = false,					
			width = 200,			
			tooltips = true,
			[ADDON.PLAYERCLASS] = {},
			configs = {},									
		},
		engine = {			
			rotationUpdate 	= .1,
			interruptUpdate	= .1,							
		},
		rotationConfigs = {					
			lock = false,			
			width = 200,			
			tooltips = true,
			configTooltips = true,					
		},	
		tracker = {						
			tooltips = true,					
		},						
	},		
}
-- ~~| Menu |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ADDON.MenuData = {		
	RotationSelecter = {	
		name = '|cff00aaffRotation Selecter',
		order = 10,
		onClick = function()
			local frame = ADDON.RotationSelecter.frame
			frame[frame:IsVisible() and "Hide" or "Show"](frame)
			ADDON.RotationSelecter.db.show = frame:IsVisible()
			AceConfigRegistry:NotifyChange(AddOnName)
		end,
		check	= function()
			return ADDON.RotationSelecter.db.show
		end,		
	},	
	ActionLog = {
		name = '|cff00aaffAction Log',
		order = 20,
		onClick = function()
			local frame = ADDON.ActionLog.frame
			frame[frame:IsVisible() and "Hide" or "Show"](frame)
			ADDON.ActionLog.db.show = frame:IsVisible()
			AceConfigRegistry:NotifyChange(AddOnName)
		end,
		check	= function()
			return ADDON.ActionLog.db.show
		end,		
	},
	Tracker = {
		name = '|cff00aaffTracker',
		order = 30,
		onClick = function()
			local frame = ADDON.Tracker.frame
			frame[frame:IsVisible() and "Hide" or "Show"](frame)
			ADDON.Tracker.db.show = frame:IsVisible()
			AceConfigRegistry:NotifyChange(AddOnName)
		end,
		check	= function()
			return ADDON.Tracker.db.show
		end,		
	},
	Options = {
		name = 'Options',
		order = 1000,
		onClick = function()
			ADDON:OpenOptions()
		end,
	},	
}

-- ~~| Options |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADDON.options = {
	type = "group",
	name = AddOnName,
	args = {
		settings = {
			order = 10,
			type = "group",
			name = "Settings",
			args = {
				minimap = {
					type = "toggle",
					name = "Minimap Button",
					order = 10,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return not ADDON.db.global.minimap.hide end,
					set = function(info,value)
						ADDON.db.global.minimap.hide = not value
						ADDON:Update()
					end,
					width = "normal",
				},
				rotationUpdate = {
					type = "range",
					name = "Rotation Update Interval",
					order = 20,
					desc = "Sets the Rotation Engine Update Interval in milliseconds.",
					min = 50, max = 500, step = 10,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return (ADDON.db.profile.engine.rotationUpdate * 1000) end,
					set = function(info,value)
						ADDON.db.profile.engine.rotationUpdate = (value / 1000)
						ADDON.Engine:SetRotationUpdate(value / 1000)
					end,
					width = "normal",					
				},
				interruptUpdate = {
					type = "range",
					name = "Interrupt Update Interval",
					order = 25,
					desc = "Sets the Interrupt Engine Update Interval in milliseconds.",
					min = 50, max = 500, step = 10,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return (ADDON.db.profile.engine.interruptUpdate * 1000) end,
					set = function(info,value)
						ADDON.db.profile.engine.interruptUpdate = (value / 1000)
						ADDON.Engine:SetInterruptUpdate(value / 1000)
						end,
					width = "normal",					
				},
				spacer = {
					order = 30,
					type = "description",
					name = " ",
					width = "full",
				},
				-- ~~ remote ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				
				-- ~~ Action Log ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				logTitle = {
					order = 1000,
					type = "description",
					name = "|cff00aaffAction Log",
					fontSize = "large",
					width = "full",
				},
				log = {
					order = 1010,
					type = "toggle",
					name = "Show",
					desc = "Show the Action Log",
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return ADDON.db.profile.actionLog.show end,
					set = function(info,value) ADDON.db.profile.actionLog.show = value; ADDON.ActionLog:Update() end,
					width = "normal",					
				},
				logTooltips = {
					order = 1020,
					type = "toggle",
					name = "Tooltips",
					desc = "Toggle Tooltips.",
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return ADDON.db.profile.actionLog.tooltips end,
					set = function(info,value) ADDON.db.profile.actionLog.tooltips = value; ADDON.ActionLog:Update() end,
					width = "normal",					
				},
				logNewline = {
					order = 1900,
					type = "description",
					name = "",					
					width = "full",
				},				
				logSpacer = {
					order = 1950,
					type = "description",
					name = " ",					
					width = "full",
				},
				-- ~~ Rtoation Selecter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				
				-- ~~ Scriptor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			},			
		},		
		debugging = {
			order = 20,
			type = "group",
			name = "Debugging",
			args = {
				rotEngine = {
					type = "toggle",
					name = "Rotation Engine",
					desc = "Rotation Engine Debugging",
					order = 10,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return ADDON.db.global.debug.rotEngine end,
					set = function(info,value)	ADDON.db.global.debug.rotEngine = value end,
					width = "normal",
				},		
				scriptVars = {
					type = "toggle",
					name = "Option Updates",
					desc = "Print configuration option updates to the chat frame",
					order = 50,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return ADDON.db.global.debug.OptUpdate end,
					set = function(info,value)	ADDON.db.global.debug.OptUpdate = value end,
					width = "normal",
				},
				dev = {
					type = "toggle",
					name = "Development",
					desc = "Addon Development Debugging",
					order = 60,
					disabled = function() return not ADDON:IsEnabled() end,
					get = function() return ADDON.db.global.debug.dev end,
					set = function(info,value)	ADDON.db.global.debug.dev = value end,
					width = "normal",
				},							
			},
		},		
	},
}